<template>
  <el-row type="flex" justify="center">
    <el-form ref="loginForm" :model="user":rules='rules' status-icon label-width="80px">
      <el-form-item label="用户名" prop="name">
        <el-input v-model="userName"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="pass">
        <el-input v-model="userPassword" type="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-upload" @click="login()">登录</el-button>
      </el-form-item>
    </el-form>
  </el-row>
</template>

<script type = "text/javascript">
  import axios from 'axios'
  export default {

    data() {
      return {
        userName: '',
        userPassword: '',
      }
    },


      methods: {
        login() {
          var url= '/emp/login'
          var data = {userName: this.userName, userPassword: this.userPassword}
          this.axios.post(url, this.qs.stringify(data)).then(res => {
            console.log(res)
            if (res.data.success==true) {
              alert('登录成功');
              this.$router.replace('/success')
            } else {
              alert('登录失败')
              this.$router.replace('/fail')
            }
          });


        }
      }
    }

    /*this.$refs.loginForm.validate((valid) => {
          if (valid) {
            if (this.user.name === '111' && this.user.pass === '111') {
              // dispatch采用Promise链式调用
              this.$store.dispatch('login', this.user).then(() => {
                this.$notify({
                  type: 'success',
                  message: '欢迎你,' + this.user.name + '!',
                  duration: 3000
                })
                this.$router.replace('/')
              })
            } else {
              this.$message({
                type: 'error',
                message: '用户名或密码错误',
                showClose: true
              })
            }
          }
          else {
            return false
          }
        })*/




</script>


